package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.www.car.viewhelper.CarTransferViewHelper;

/**
 * @author zhangxueliang
 * 高级搜索，过户信息修改
 */
public class CarSearchTransferInputAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarSearchTransferInputAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		CarTransferViewHelper transferHelper = new CarTransferViewHelper();
		transferHelper = (CarTransferViewHelper)uc.getAttribute(CarSearchTransferDetailAction.CARTRANSFERVIEWHELPER);
		Codes code = Codes.getInstance();
		transferHelper.setNewOwnerTypeList(code.getCodeslistByItemId(Codes.CAR_OWNER));
		transferHelper.setTransferTypeList(code.getCodeslistByItemId(Codes.TRANSFER_TYPE));
		transferHelper.setGainTypeList(code.getCodeslistByItemId(Codes.GAIN_TYPE));
		transferHelper.setNewOwnerType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.CAR_OWNER, transferHelper.getNewOwnerType())));
		transferHelper.setTransferType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.TRANSFER_TYPE, transferHelper.getTransferType())));
		transferHelper.setGainType(String.valueOf(code.getItemCodeByItemIdAndItemValue(Codes.GAIN_TYPE, transferHelper.getGainType())));
		if(StringUtil.isNullOrBlank(transferHelper.getMoveOutCity())){
			transferHelper.setMoveOutCity("市");
		}else{
			transferHelper.setMoveOutCity(transferHelper.getMoveOutCity());
		}
		if(StringUtil.isNullOrBlank(transferHelper.getMoveOutProvince())){
			transferHelper.setMoveOutProvince("省");
		}else{
			transferHelper.setMoveOutProvince(transferHelper.getMoveOutProvince());
		}
		
		transferHelper.setPrice(transferHelper.getPrice());
		
		request.setAttribute(TmsConstants.TRANSFERHELPER, transferHelper);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
